package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.IWorkLogService;
import com.igeekhome.pojo.BlackList;
import com.igeekhome.pojo.CommonWord;
import com.igeekhome.pojo.WorkLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 工作日志 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/workLog")
public class WorkLogController {

    @Autowired
    private IWorkLogService iWorkLogService;
    @RequestMapping("/wl")
    public String wl(Model model, HttpSession session, @RequestParam("value")String value, @RequestParam("current")Integer current, @RequestParam("size")Integer size){


        IPage<WorkLog> page =new Page<>(current,size);
        QueryWrapper<WorkLog>qw = new QueryWrapper<>();
        qw.like("operateperson",value).or().like("operatoraction",value).or().like("operatorclass",value);
        IPage<WorkLog> page1=this.iWorkLogService.page(page,qw);
        List<WorkLog> list = page1.getRecords();
        session.setAttribute("work",this.iWorkLogService.count());
        long pagesCount=page1.getPages();
        model.addAttribute("list",list);
        model.addAttribute("pagesCount",pagesCount);

        return "workLog";
    }

    @RequestMapping("/addsuccess")
    public String addwl(WorkLog workLog){
        LocalDateTime newLDT = LocalDateTime.now();

        int year = newLDT.getYear();//年
        int month = newLDT.getMonth().getValue();//月
        int dayOfMonth = newLDT.getDayOfMonth();//日
        int hour = newLDT.getHour();//时
        int minute = newLDT.getMinute();//分
        int second = newLDT.getSecond();//


        WorkLog w = new WorkLog(workLog.getOperateperson(),workLog.getOperatoraction(),workLog.getOperatorclass(),newLDT);
        System.out.println("添加操作成功");
        this.iWorkLogService.save(w);

        return "redirect:/workLog/wl?current=1&size=6";

    }


}

